package main

import (
	"fmt"
	"time"
)

func main() {
	// 1. 获取当前时间
	now_time := time.Now()
	fmt.Printf("%v, %[1]T\n", now_time)
	// 2021-10-30 13:12:41.714128596 +0800 CST m=+0.000068618, time.Time

	// 2. 获取年月日
	fmt.Println(now_time.Year())
	fmt.Println(int(now_time.Month()))
	fmt.Println(now_time.Day())
	fmt.Println(now_time.Hour())
	fmt.Println(now_time.Minute())
	fmt.Println(now_time.Second())

	// 3. 格式化时间 输出
	// 3.1 Sprinf(format, str...)
	str := fmt.Sprintf("%d-%d-%d %d:%d:%d", now_time.Year(), now_time.Month(), now_time.Day(),
		now_time.Hour(), now_time.Minute(), now_time.Second())
	fmt.Println(str) // 2021-10-30 13:16:31

	// 3.2 time.Now().Format
	str2 := now_time.Format("2006/01/02 15:04:05") // 固定写法
	fmt.Println(str2)                              // 2021/10/30 13:19:03

	str3 := now_time.Format("2006-01-02")
	fmt.Println(str3) // 2021-10-30

	str4 := now_time.Format("15:04:05")
	fmt.Println(str4) // 13:19:44
}
